home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1990 / Feb 90 / MacApp.Tech$ 2⁄23⁄90 / 0709-Re Undoable commands-Feb90 < prev    next >
Encoding:
Text File  |  1991-03-06  |  3.3 KB  |  87 lines  |  [TEXT/GEOL]

  1. Item forwarded  by  A33          to A34
  2.  
  3. Item    3277951                         18-Feb-90        15:44PST
  4.  
  5. From:   D0416                           Futuresoft System Design,PRT
  6.  
  7. To:     D5295                           Reseach SW Design, D Goldman,PRT
  8.  
  9. cc:     MACAPP.TECH$                    MacApp Technical
  10.  
  11. Sub:    RE-Undoable commands
  12.  
  13. Hi Dave,
  14.  
  15. Glad to see the Guerrilla effort (The Class Room) off and running. It will
  16. benefit us all!
  17.  
  18. RE: My problem is that we're performing a TControlTracker command when my
  19. >TControl.TrackMouse sees the mouse-up. We need to let
  20. >TControlTracker.TrackMouse return gNoChanges, and then somehow tell MacApp to
  21. >perform my new undoable command.
  22. >(Simply having TrackMouse return myCommand won't work.)
  23. >
  24. >Bottom line (simple???) question: how do you get a mouse-tracking command
  25. >object to create and perform a different command object?
  26.  
  27. Hmm… maybe this (somewhat hacky) approach will work. I haven’t tried this
  28. myself so no guarantees:
  29.  
  30. Add a method (function) to TYourControl class called
  31. TYourControl.MakeUndoableTracker(…) which instantiates and returns an undoable
  32. command object. Then in TYourControlTracker.TrackMouse you call
  33. TYourControl(fControl).MakeUndoableTracker(…) and return the newly created
  34. undoable command as the TYourControlTracker.TrackMouse result. I believe MacApp
  35. will take care of undoable activities from that point on.
  36.  
  37. FUNCTION TYourControl.MakeUndoableTracker(…): TUndoableCommand;
  38.     VAR anUndoableCmd:  TUndoableCommand;
  39.  
  40.     BEGIN
  41.     MakeUndoableTracker := NIL;   {first assume you won't make one}
  42.     IF the situation warrants one THEN  {create a command and return it}
  43.         BEGIN
  44.         NEW(anUndoableCmd);   {instantiate it}
  45.         FailNIL(anUndoableCmd);
  46.         anUndoableCmd.IAnUndaobleCommand;
  47.         MakeUndoableTracker := anUndoableCmd; {return it}
  48.         END;
  49.     END;
  50.  
  51. FUNCTION TYourControlTracker.TrackMouse(aTrackPhase: TrackPhase; VAR
  52. anchorPoint, previousPoint, nextPoint: VPoint; mouseDidMove: BOOLEAN):
  53. TCommand; OVERRIDE;
  54.     VAR aCommand: TCommand;
  55.         newCommand: TCommand;
  56.  
  57.     BEGIN
  58.         {call INHERITED to enable default behavior}
  59.     aCommand := INHERITED TrackMouse(aTrackPhase,anchorPoint,…);
  60.     IF aCommand = SELF THEN {command still alive, change to an undoable cmd}
  61.         BEGIN
  62.             {get yourControl to make UNDOABLE command if appropriate}
  63.         newCommand := TYourControl(fControl).MakeUndoableCommand(…);
  64.         IF newCommand <> NIL THEN   {we have a new UNDOABLE command}
  65.             aCommand := newCommand; {set up to return it}
  66.         END;
  67.     TrackMouse := aCommand;
  68.     END;
  69.  
  70. NOTE: the ellipse (“…”) in the the parm areas means fill in as appropriate
  71.  
  72. MacApp should “see” that you changed the tracker command, free the old command
  73. and continue calling track methods of the now new UNDOABLE command. You can
  74. check this out in the MacApp source code. Look at the local procedure TrackOnce
  75. in the TApplication.TrackMouse procedure. It all finally unwinds to this code.
  76. WARNING: None of this works for controls subclassed from TCtlMgr since TCtlMgr
  77. does its stuff via DoChoice method without trackers.
  78.  
  79. The whole issue of returning commands to MacApp is supposed to be really slick
  80. and flexible in MA 2.0 final. In the mean time I hope the above approach guides
  81. you to a solution.
  82.  
  83. -Ken Addison
  84.  
  85.  
  86.  
  87.